package com.rmuti.datastructure.list.ui;

import java.awt.Dimension;

import javax.swing.JFrame;

import com.rmuti.datastructure.list.ArrayList;

import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseMultigraph;
import edu.uci.ics.jung.graph.util.EdgeType;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;

public class SimpleGraphView {
	Graph<String, String> g;

	/** Creates a new instance of SimpleGraphView */
	public SimpleGraphView() {
		// Graph<V, E> where V is the type of the vertices and E is the type of
		// the edges
		g = new SparseMultigraph<String, String>();
		// Add some vertices. From above we defined these to be type Integer.
		// g.addVertex("a");
		// g.addVertex("b");
		// g.addVertex("c");
		// Note that the default is for undirected edges, our Edges are Strings.
		// g.addEdge("Edge-A", "a", "b");
		// g.addEdge("Edge-B", "a", "c");

		ArrayList arrayList = new ArrayList();
		arrayList.add("a");
		arrayList.add("b");
		arrayList.add("c");
		arrayList.add("d");
//		arrayList.add("e");

		for (int i = 0; i < arrayList.size(); i++) {
			g.addVertex(arrayList.get(i).toString());
		}

		int loop = 3;
//		if(arrayList.size()%2==0){
//			loop = (int) (Math.floor(arrayList.size() / 2.0) + 1);
//		} else {
//			loop = (int) Math.ceil(arrayList.size()/2.0);
//		}
		for (int i = 0; i < loop; i++) {
			g.addEdge(i+"", arrayList.get(i).toString(), arrayList.get(i+1).toString(),EdgeType.DIRECTED);
		}

	}

	public static void main(String[] args) {
		SimpleGraphView sgv = new SimpleGraphView(); // We create our graph in
														// here
		// The Layout<V, E> is parameterized by the vertex and edge types
		Layout<String, String> layout = new CircleLayout(sgv.g);
		layout.setSize(new Dimension(300, 300)); // sets the initial size of the
													// layout space
		// The BasicVisualizationServer<V,E> is parameterized by the vertex and
		// edge types
		BasicVisualizationServer<String, String> vv = new BasicVisualizationServer<String, String>(
				layout);
		vv.setPreferredSize(new Dimension(350, 350)); // Sets the viewing area
														// size

		JFrame frame = new JFrame("Simple Graph View");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add(vv);
		frame.pack();
		frame.setVisible(true);
	}

}
